package seg.tef4.whms.util.dialog;

import android.app.DatePickerDialog;
import android.content.Context;
import android.graphics.Color;
import android.widget.DatePicker;
import android.widget.Toast;

import com.example.scan.R;

import java.lang.reflect.Field;
import java.util.Calendar;
import java.util.Locale;

public class DateRangePicker {
    private Calendar startCalendar;
    private Calendar endCalendar;

    public DateRangePicker() {
        // 初始化起始日期和结束日期的 Calendar 对象
        startCalendar = Calendar.getInstance();
        endCalendar = Calendar.getInstance();
    }

    public void showDatePickerDialog(final Context context) {
        DatePickerDialog startPickerDialog = new DatePickerDialog(
                context,R.style.CustomDatePickerDialog,
                (view, year, month, dayOfMonth) -> {
                    startCalendar.set(Calendar.YEAR, year);
                    startCalendar.set(Calendar.MONTH, month);
                    startCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                },
                startCalendar.get(Calendar.YEAR),
                startCalendar.get(Calendar.MONTH),
                startCalendar.get(Calendar.DAY_OF_MONTH)
        );


        startPickerDialog.show();
    }

    private void showEndDatePickerDialog(final Context context) {
        DatePickerDialog endDatePickerDialog = new DatePickerDialog(
                context,R.style.CustomDatePickerDialog,
                (view, year, month, dayOfMonth) -> {
                    endCalendar.set(Calendar.YEAR, year);
                    endCalendar.set(Calendar.MONTH, month);
                    endCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                },
                endCalendar.get(Calendar.YEAR),
                endCalendar.get(Calendar.MONTH),
                endCalendar.get(Calendar.DAY_OF_MONTH)
        );
        endDatePickerDialog.show();
    }

    /**
     * @description 检查结束时间是否晚于开始时间
     * @return
     */
    private boolean checkTime(){
        if (endCalendar.after(startCalendar))
            return true;
        else
            return false;
    }

    private String formatDate(Calendar calendar) {
        // Format the date as needed, e.g., "YYYY-MM-DD"
        return String.format("%d-%02d-%02d",
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH) + 1,
                calendar.get(Calendar.DAY_OF_MONTH));
    }

}
